<?php

class Application_Model_CategoryMapper {
    protected $_db;

    const ID = 'cat_id';
    const TEXT = 'cat_text';
    const URL = 'cat_url';

    public function  __construct()
    {
        $this->_db = Zend_Registry::get('db_adaptor');
    }

    public function getAll()
    {
        $q = 'SELECT * FROM category';
        return $this->_db->fetchAll($q);
    }

    /**
     *
     * @param string|int $param Category ID or url
     * 
     */
    public function find($param)
    {
        $q = "SELECT * FROM category WHERE `cat_id` = '$param' OR `cat_url` = '$param'";
        return $this->_db->fetchRow($q);
    }

    public function dbEntryToCategoryObj(array $dbEntry){
        $options = array (
            'id'   => $dbEntry[self::ID],
            'text' => $dbEntry[self::TEXT],
            'url'  => $dbEntry[self::URL]
        );

        return new Application_Model_Category($options);
    }

}

?>
